package cn.xfdzx.android.apps.shop.activity;


import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.apps.Constants;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.bean.RuleBean;
import cn.xfdzx.android.apps.shop.contract.RuleContract;
import cn.xfdzx.android.apps.shop.presenter.RulePresenter;
import cn.xfdzx.android.apps.shop.util.StatusBarUtil;

/**.
 * 运费说明，送达时间说明页面
 * */

public class OrderFeightDesActivity extends BaseMvpActivity<RulePresenter>implements RuleContract.View {

    @BindView(R.id.iv_back)
    ImageView ivBack;      //标题栏-左边按钮
    @BindView(R.id.tv_title)
    TextView tv_title;      //标题
    @BindView(R.id.tv_agreement)
    TextView tvAgreement;
    @BindView(R.id.ll_state)
    LinearLayout llState;

    private RelativeLayout.LayoutParams item_bar;
    private String type = "";
    private String state = "";
    @Override
    public int getLayoutId() {
        return R.layout.activity_orderdes;
    }

    @Override
    public void initView() {
        initHigh();
        mPresenter = new RulePresenter();
        mPresenter.attachView(this);
        type = getIntent().getStringExtra("type");
        state = getIntent().getStringExtra("state");
        if (state.equals("1")) {//送达时间说明
            tv_title.setText("配送时间说明");

        } else if (state.equals("2")){//运费说明
            tv_title.setText("运费规则说明");

        }else if (state.equals("3")){//运费说明
            tv_title.setText("服务费说明");

        }

        mPresenter.getRule(type,state);
    }

    private void initHigh() {
        item_bar = (RelativeLayout.LayoutParams) llState.getLayoutParams();
        item_bar.height = StatusBarUtil.getStatusBarHeight(this);
        llState.setLayoutParams(item_bar);
    }

    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:    //返回按钮点击
                finish();
                break;
        }
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }

    @Override
    public void getRuleSuccess(RuleBean bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            tvAgreement.setText(Html.fromHtml(bean.getData().getContent()));
        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    protected boolean isUseFullScreenMode() {
        return true;
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
